#include "qtthreadmodel.h"
#include "ui_qtthreadmodel.h"

#include "DarberThread.h"

QtThreadModel::QtThreadModel(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::QtThreadModel)
{
    ui->setupUi(this);
    // 此处，将按键BtnStart按下，将启动线程——包括创建和打开线程，均在initThread的实现中
    connect(ui->BtnStart, &QPushButton::clicked, this, &QtThreadModel::initThread);
}

QtThreadModel::~QtThreadModel()
{
    delete ui;
}

void QtThreadModel::initThread(void)
{
    WorkerThread *workerThread = new WorkerThread(this);

    // 此处，是为了注册这个线程结束时的槽函数
    connect(workerThread, &WorkerThread::finished, this, &QtThreadModel::finishThread);

    // 启动线程
    workerThread->start();
}

void QtThreadModel::finishThread(void)
{
    ui->textBack->append("thread back!");
}

void QtThreadModel::on_BtnStart_clicked()
{
    ui->textSend->append("send ...");
}
